package com.cangxuan.backend.service.impl;

import com.cangxuan.backend.entity.User;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * 服务实现类 基类
 */
public class BaseServiceImpl {

    protected User getCurrentUser() {
        //从Security上下文对象中获取当前请求者的身份认证信息
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        System.out.println("authentication.getPrincipal():"+authentication.getPrincipal());
        User user = (User) authentication.getPrincipal();
        return user;
    }

    protected String getCurrentDeviceId() {
        //从Security上下文对象中获取当前请求者的身份认证信息
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        return authentication.getCredentials().toString();
    }
}
